#include "GowildControlCmd.h"

GowildControlCmd::GowildControlCmd(QObject *parent) :
    BaseCmd(parent)
{
    this->m_protocolType = ProtocolType::GowildProtocol;
    this->m_functionCode = FunctionCode;
}

Package GowildControlCmd::toPackage()
{
    Package package;
    return package;
}

void GowildControlCmd::unPackage(Package package)
{
    QByteArray body = package.body();

    QJson::Parser parser;
    QVariantMap result = parser.parse(body, NULL).toMap();
    QVariantList dataList = result["data"].toList();

    foreach (const QVariant &data, dataList)
    {
        Gowild::ControlParamStruct controlParam;
        QVariantMap map = data.toMap();

        int id = map["id"].toInt();
        QString action = map["action"].toString();
        QString attribute = map["attribute"].toString();
        QString attributeValue = map["attributeValue"].toString();
        QString mode = map["mode"].toString();
        QString name = map["name"].toString();
        QString room = map["room"].toString();
        QString scene = map["scene"].toString();
        QString state = map["state"].toString();

        controlParam.setId(id);
        controlParam.setAction(action);
        controlParam.setAttribute(attribute);
        controlParam.setAttributeValue(attributeValue);
        controlParam.setMode(mode);
        controlParam.setName(name);
        controlParam.setRoom(room);
        controlParam.setScene(scene);
        controlParam.setState(state);
        m_controlParamList.append(controlParam);
    }

}
QList<Gowild::ControlParamStruct> GowildControlCmd::controlParamList() const
{
    return m_controlParamList;
}

void GowildControlCmd::setControlParamList(const QList<Gowild::ControlParamStruct> &controlParamList)
{
    m_controlParamList = controlParamList;
}



